package com.Alex.ComicOnline;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.ImageView;

public class CopyOfComicOnline extends Activity {
	private String imageUrl;
	private ImageView imageView;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		imageUrl = "http://imgcache.qq.com/tuangou/autoimg/201103/104494/static-team-2011-0309-12996533365503.jpg";
		imageView = (ImageView) findViewById(R.id.picture);

		showImage();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		return true;
	}

	private void showImage() {
		URL url;
		try {
			url = new URL(imageUrl);
		} catch (MalformedURLException e) {
			Log.e("URL format error.", e.getMessage());
			return;
		}
		try {
			URLConnection conn = url.openConnection();
			conn.connect();
			InputStream in = conn.getInputStream();
			BufferedInputStream bis = new BufferedInputStream(in);
			Bitmap bitmap = BitmapFactory.decodeStream(bis);
			if (bitmap != null)
				imageView.setImageBitmap(bitmap);
		} catch (IOException e) {
			Log.e("Get image error.", e.getMessage());
		}
	}
}